﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ZY8.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UplodFilesController : ControllerBase
    {
        public UplodFilesController(IWebHostEnvironment env)
        {
            Env = env;
        }

        public IWebHostEnvironment Env { get; }
        [HttpPost]
        public IActionResult Uplod(IFormFile file) 
        {
            string newfilename=Guid.NewGuid().ToString();
            string path=Env.WebRootPath+@"\pic\"+file.FileName;
            using (FileStream fs = System.IO.File.Create(path)) 
            {
                file.CopyTo(fs);
                fs.Close();
            }
            return Ok("/pic/" + file.FileName);
        }
    }
}
